<?php
  define('IN_ECS', true);
  
  define(ROOT_PATH, str_replace('exchange_rate.php', '', str_replace('\\', '/', __FILE__)));
  require_once('plugins/simple_html_dom.php');
  require_once(ROOT_PATH.'ty/collect_info/ExchangeRateService.php');
  require_once(ROOT_PATH.'plugins/cls_json.php');
  
  $exchangeRateService = new ExchangeRateService();
  
  $action  = isset($_REQUEST['act']) ? trim($_REQUEST['act']) : 'county_rate';
  
  if($action == 'county_rate'){
     $html = $exchangeRateService->getLastExchangeRateList();
     $json = new JSON();
    $jsonString = $json->encode(array('content'=>$html));
     exit($jsonString);
     //exit('{"content":"'.$html.'"}');
  }
  elseif($action == 'stock_rate'){
      $stockTable = $exchangeRateService->getStockRateListHtml();

      $json = new JSON();
      $jsonString = $json->encode(array('content'=>$stockTable));
      //echo $jsonString;
      exit($jsonString);
      //exit($stockTable);
  }
  elseif($action == 'county_stock'){
      $countyTable = $exchangeRateService->getLastExchangeRateList();
      $stockTable = $exchangeRateService->getStockRateListHtml();
      
      $json = new JSON();
      $result = $json->encode(array('county'=>$countyTable, 'stock'=>$stockTable));
      exit($result);
  }
  
?>
